package dm71.espil.REST.Tasks;

import dm71.espil.REST.DataService;
import dm71.espil.REST.LoginParameters;
import dm71.espil.activities.LoginActivity;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

/**
 * TODO Put here a description of what this class does.
 *
 * @author Moulde.
 *         Created Dec 22, 2011.
 */
public class LoginTask extends AsyncTask<LoginParameters, Object, Boolean>
{
	private ProgressDialog dialog;
	protected Context applicationContext;
	protected LoginActivity callingActivity;
	
	public LoginTask(LoginActivity activity)
	{
		this.applicationContext = activity.getApplicationContext();
		this.callingActivity = activity;
	}
	
	@Override
	protected void onPreExecute()
	{
		this.dialog = ProgressDialog.show(callingActivity, "Logger ind", "Vent venligst...", true);
	}

	protected Boolean doInBackground(LoginParameters... params) 
	{
		Log.i("ESPIL", "DoInBackground");
		DataService ds = new DataService();
		return ds.Login(params[0].getUsername(), params[0].getPassword());
	}
	
	protected void onPostExecute(Boolean result) 
	{
		this.dialog.cancel();
		callingActivity.LogInComplete(result);
	}
}
